package cs301.msflags;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.SurfaceView;

/**
 * The view which displays the game board.
 * 
 * @author John Olennikov
 * @author Kyanne Mayfield
 * @author Allie Seibert
 * @author Emilia Holbik
 * @version 12/7/2012
 *
 *          This class is the object on which to draw the Board.
 */

public class MSFlagsSurfaceView extends SurfaceView {
	
	/**
	 * The current board to be drawn
	 */
	private Board board;
	
	/**
	 * The width of the area in which the board is drawn
	 */
	private int screenWidth = 0;
	
	/**
	 * The height of the area in which the board is drawn
	 */
	private int screenHeight = 0;

	/**
	 * Constructor
	 * 
	 * Initializes the view.
	 * 
	 * @param context  the context of the view
	 * @param attrs  attributes from the XML
	 */
	public MSFlagsSurfaceView(Context context, AttributeSet attrs) {
		super(context, attrs);
		setWillNotDraw(false);
	}
	
	/**
	 * Gets the screen's width and height.
	 * 
	 * @param w  the current width of the screen 
	 * @param h  the current height of the screen
	 * @param oldw  the previous width of the screen
	 * @param oldh  the previous height of the screen
	 */
	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh)
	{
		super.onSizeChanged(w, h, oldw, oldh);
		this.screenWidth = w;
		this.screenHeight = h;
	}
	
	/**
	 * Set the board to be drawn.
	 * 
	 * @param board  the current game board.
	 */
	public void setCurrentBoard(Board board)
	{
		this.board = board;
	}

	/**
	 * Draws the board.
	 * 
	 * @param canvas  the canvas on which to draw the board
	 */
	public void draw(Canvas canvas)
	{
		if(board != null)
		{
			board.draw(canvas, screenHeight, screenWidth);
		}
	}

}

